<template>
    <div class="sub-layout user-detail-content">
        <div class="sub-sidebar">
            <div class="search-bar">
                <div class="search-box">
                    <el-select v-model="search.value" placeholder="搜索用户..." filterable remote :remote-method="searchMethod" :loading="search.loading"
                        @change="searchChange">
                        <el-option v-for="item in search.list" :key="item.id" :label="item.name" :value="item.id"></el-option>
                    </el-select>
                    <i class="icon i-search"></i>
                </div>
                <permission class="add" permission-key="user:addDept">
                    <a @click="showEditLayer(0)">
                        <i class="icon i-plus"></i>
                    </a>
                </permission>
            </div>
            <div class="side-nav">
                <el-tree node-key="id" :props="deptDefaultProps" :data="deptList" @node-click="nodeClick"></el-tree>
            </div>
        </div>
        <div class="sub-main">
            <div class="content">
                <div class="section section-panel">
                    <div class="panel-title">
                        <span class="title">查看用户</span>
                        <div class="title-right">
                            <button class="btn-cancel" @click="goBack">返回</button>
                            <permission permission-key="user:updateUser">
                                <router-link :to="{path: '/system/user/edit', query: {userid: userId}}">
                                    <button>修改</button>
                                </router-link>
                            </permission>
                        </div>
                    </div>
                    <div class="panel-content">
                        <div class="form-box" v-if="detail">
                            <div class="form-item">
                                <label class="form-label">用户姓名</label>
                                <div class="form-text" v-text="detail.name?detail.name:'-'"></div>
                            </div>
                            <div class="form-item">
                                <label class="form-label">邮箱地址</label>
                                <div class="form-text" v-text="detail.email?detail.email:'-'"></div>
                            </div>
                            <div class="form-item">
                                <label class="form-label">所属公司</label>
                                <div class="form-text" v-text="detail.companyName?detail.companyName:'-'"></div>
                            </div>
                            <div class="form-item">
                                <label class="form-label">所属部门</label>
                                <div class="form-text" v-text="detail.departmentName?detail.departmentName:'-'"></div>
                            </div>
                            <div class="form-item">
                                <label class="form-label">职位</label>
                                <div class="form-text" v-text="detail.position?detail.position:'-'"></div>
                            </div>
                            <div class="form-item">
                                <label class="form-label">身份证号</label>
                                <div class="form-text" v-text="detail.identity?detail.identity:'-'"></div>
                            </div>
                            <div class="form-item">
                                <label class="form-label">手机号</label>
                                <div class="form-text" v-text="detail.phone?detail.phone:'-'"></div>
                            </div>
                            <div class="form-item">
                                <label class="form-label">登录密码</label>
                                <div class="form-text" v-text="detail.password?detail.password:'-'"></div>
                            </div>
                            <div class="form-item form-block">
                                <label class="form-label">角色</label>
                                <div class="form-text" v-if="detail.roles">
                                    <span v-for="item in detail.roles">{{item.name}}</span>
                                </div>
                                <div class="form-text" v-else>-</div>
                            </div>
                            <div class="form-item form-block">
                                <label class="form-label">所监察产品类型</label>
                                <div class="form-text" v-if="detail.products">
                                    <span v-for="item in detail.products">{{item.name}}</span>
                                </div>
                                <div class="form-text" v-else>-</div>
                            </div>
                            <div class="form-item form-block">
                                <label class="form-label">监管内容</label>
                                <div class="form-text" v-if="detail.sales">
                                    <span v-for="item in detail.sales">{{item.name}}</span>
                                </div>
                                <div class="form-text" v-else>-</div>
                            </div>
                            <div class="form-item form-block">
                                <label class="form-label">备注信息</label>
                                <div class="form-text" v-text="detail.remark?detail.remark:'-'"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- 编辑layer -->
        <layer :data="editLayerData" @on-cancel="closeEditLayer" @on-ok="editLayerConfirm">
            <div class="el-form">
                <div class="el-form-item is-required" :class="{'is-error':editLayerData.error}">
                    <label class="el-form-item__label" style="width: 100px;">类别名称</label>
                    <div class="el-form-item__content" style="margin-left: 112px;">
                        <div class="el-input">
                            <input autocomplete="off" type="text" validateevent="true" class="el-input__inner" placeholder="请输入类别名称" v-model="editLayerData.name"
                                @blur="layerInputBlur">
                        </div>
                        <div class="el-form-item__error" v-if="editLayerData.error">请输入类别名称</div>
                    </div>
                </div>
            </div>
        </layer>
    </div>
</template>

<script>
    import './userDetail.less'
    import userManage from '@/mixins/userManage'
    export default {
        name: 'userDetail',
        mixins: [userManage],
        data() {
            return {
                detail: {}
            }
        },
        computed: {
            userId() {
                return this.$route.query.userid || 0
            }
        },
        mounted() {
            this.$store.dispatch('setBreadData', [
                {
                    name: '系统管理'
                },
                {
                    name: '用户管理',
                    path: '/system/user'
                },
                {
                    name: '查看用户'
                }
            ])
            this.getUserDetail()
        },
        methods: {
            // 返回
            goBack() {
                this.$router.go(-1)
            },
            getUserDetail() {
                api.getUserDetail({
                    id: this.userId
                }).then(res => {
                    this.detail = res
                }).catch(res => {
                    console.log(res)
                })
            }
        },
        watch: {
            userId() {
                this.getUserDetail()
            }
        }
    }
</script>